package com.person.nacos.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.person.common.CommonResult;
import com.person.nacos.fallbackhandler.GlobalFallbackHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangfc
 * @date 2021/7/26 10:59
 */
@RestController
public class RoteLimiteController {

    @GetMapping("/testSentinel")
    @SentinelResource(value = "testSentinel",blockHandler = "fallbackTestSentinel")
    public CommonResult testSentinel(){
        return CommonResult.ok(200,"success","testSentinel");
    }

    public CommonResult fallbackTestSentinel(BlockException exception){
        return CommonResult.error("failure","fallbackTestSentinel");
    }

    @GetMapping("/globalFollowHandler")
    @SentinelResource(value = "globalFollowHandler",
            blockHandlerClass = GlobalFallbackHandler.class,
            blockHandler = "fallbackHandler1")
    public CommonResult globalFollowHandler(){
        return CommonResult.ok(200,"success","globalFollowHandler");
    }
}
